package com.felix.test;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.felix.test.ChatTest.MyThread;
import com.g3net.tool.HttpUtils;


public class ChatTest2 {
	public static String sendURL="http://localhost:8080/shun2/Auto?funid=11&tid=0&cid=409&send=18&rec=14";
	public static String GETURL="http://localhost:8080/shun2/Auto?funid=11&tid=1&cid=409&send=14&rec=18&pmkey="; 
	public static int mpkey=0;
	public static class MyThread extends Thread {
		@Override
		public void run() {
			
			String res=null;
			while (true) {
				try {
					sleep(1000);
					res = HttpUtils.post(GETURL+mpkey, new HashMap<String, String>(), "utf-8",
					"utf-8");
					
					mpkey=ChatXml.showMsg(res);
					


				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	public static void sendMessage(String msg){
//		String url=sendURL+msg;
		String res = null;
		Map<String, String> map=new HashMap<String, String>();
		map.put("msg", msg);
		map.put("name", "我叫18");
		try {
			res = HttpUtils.post(sendURL,map, "utf-8",
					"utf-8");
			mpkey=ChatXml.afterSend(res);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		System.out.println("B启动一个线程，读取消息...");
		new MyThread().start();
		while(true){
			System.out.print("请输入：");
			Scanner scanner=new Scanner(System.in);
			String mms=scanner.next();
			sendMessage(mms);
			System.out.println("发送完毕。");
		}
		
	}
	
	


}


